import java.lang.reflect.Field;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-06-07
 * Time: 11:11
 */
//知识点扩展  Collection的用法，Map的用法，反射
public class TestDemo {

    public static String myreverse(String str,int begin , int end){
        char[] ch = str.toCharArray();
        char arr;
        while(begin < end){
            arr = ch[begin];
            ch[begin] = ch[end];
            ch[end] = arr;
            begin++;
            end--;
        }
        String.valueOf(ch);
        return String.copyValueOf(ch);
       // return new String(ch);
    }
    public static void main(String[] args) {
        String s1 = "asdsaasd";
        String s2 = myreverse(s1,0,s1.length()-1);
        System.out.println(s2);
    }
    //@Deprecated  此注解表明该方法已经被弃用
    @Deprecated
    public static void func(){
        System.out.println("1");
    }

    public static void main4(String[] args) {
//        func();
        String s = "name=zhangsan&age=18";
        String[] str = s.split("&");
        for(String s1:str){
            String[] str2 = s1.split("=");
            for(String s2: str2){
                System.out.println(s2);
            }
        }
    }
    public static void main3(String[] args) throws NoSuchFieldException, IllegalAccessException {
        String s1 = "hello";
        // 反射
        Class c1 = String.class;
        Field field = c1.getDeclaredField("value");
        field.setAccessible(true);
        char[] val = (char[]) field.get(s1);
        val[0] = 'g';
        System.out.println(val);
    }
    public static void main2(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("周灿1号","肖亮1号");
        map.put("周灿2号","肖亮2号");
        map.put("周灿3号","肖亮3号");
        System.out.println(map);
        System.out.println(map.get("周灿3号"));
        System.out.println(map.get("肖亮2号"));
        System.out.println(map.isEmpty());
        System.out.println(map.getOrDefault("肖亮2号", "周灿2号"));
        System.out.println(map.containsKey("周灿2号"));//不可以有重复的key
        System.out.println(map.containsValue("肖亮1号"));//可以有重复的value
        System.out.println(map.size());

        System.out.println("=============================");

        Set<Map.Entry<String,String>> entrySet = map.entrySet();

        for(Map.Entry<String,String> x:entrySet){
            System.out.println(x.getKey() + "=>" +x.getValue());
        }
    }
    public static void main1(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("bit");
        collection.add("Java105");
        collection.add("刘宇豪");
        collection.add("20");
        System.out.println(collection);
//        collection.clear();
//        System.out.println(collection);
        System.out.println(collection.isEmpty());
        collection.remove("20");
        System.out.println(collection);
        System.out.println(collection.size());
        Object[] objects = collection.toArray();
        System.out.println(Arrays.toString(objects));

    }
}
